package com.fau.om.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 订单信息表
 * @author liy
 * @datetime 2014年9月12日,上午10:52:45
 */
@Entity
@Table(name = "medical_orders")
public class MedicalOrders implements Serializable, JSONAware{

	private static final long serialVersionUID = -6108594727060510669L;

	private String id;
	private String serialNum;		// 编号
	private String status;			// 订单状态
	private String name;			// 收货人姓名
	private String contactNo;		// 联系电话
	private String provinceId; 		// 省份id
	private String cityId; 			// 城市id
	private String districtId; 		// 区县id
	private String address;			// 详细地址
	private String zipCode;			// 邮编
	private String customerId;		// 客户id
	private String ordersRemark;	// 备注
	private String payType;			// 支付方式
	private String invoice;			// 是否开发票 0否1是
	private String mediaId;			// 媒体id
	private String nature;			// 订单性质
	private String expressId;		// 物流公司id
	private BigDecimal payment;		// 货款
	private BigDecimal freight;		// 运费
	private BigDecimal receivable;	// 应收金额
	private BigDecimal amountPaid;	// 实收金额
	private Integer usePoints;		// 使用积分
	private Integer points;			// 本单积分
	private Integer useRed;			// 使用红包
	private Integer red;			// 本单红包
	private String allocateGrade;	// 分配级别
	private String cusSerId;		// 客服代表id
	private String cusSerName;		// 客服代表姓名
	private String hospitalId;		// 医院id
	private String centerId;		// 中心id
	private String groupId;			// 组id
	private String checkUserId;		// 用户id(订单分配核单元)
	private String centerName;		// 中心id
	private String groupName;		// 组名称
	private String checkUserName;	// 用户名称
	
	private Date alloateTime;				// 分配时间
	private Date createTime = new Date();	// 创建时间
	private Date updateTime = new Date();	// 修改时间
	
	private MedicalProvince province;		// 省
	private MedicalCity city;				// 市
	private MedicalDistrict district;		// 区
	private MedicalMediaInfo media;			// 媒体
	
	private Date startTime;			// 查询开始时间
	private Date endTime;			// 查询结束时间
	private String keyType;			// 字典表类型
	private String keyPid;			// 字典表父id
	private String listType;		// 列表类型
	private String reasonType;		// 不通过原因类别
	private String reasonRemark;	// 不通过原因备注
	private BigDecimal totalMoney;	// 订单总金额
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "serial_num", length = 50)
	public String getSerialNum() {
		return serialNum;
	}

	public void setSerialNum(String serialNum) {
		this.serialNum = serialNum;
	}

	@Column(name = "status", length = 30)
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Column(name = "cus_ser_id", length = 32)
	public String getCusSerId() {
		return cusSerId;
	}

	public void setCusSerId(String cusSerId) {
		this.cusSerId = cusSerId;
	}
	
	@Column(name = "name", length = 10)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "contact_no", length = 20)
	public String getContactNo() {
		return contactNo;
	}

	public void setContactNo(String contactNo) {
		this.contactNo = contactNo;
	}

	@Transient
	public String getProvinceId() {
		return provinceId;
	}

	public void setProvinceId(String provinceId) {
		this.provinceId = provinceId;
	}

	@Transient
	public String getCityId() {
		return cityId;
	}

	public void setCityId(String cityId) {
		this.cityId = cityId;
	}

	@Transient
	public String getDistrictId() {
		return districtId;
	}

	public void setDistrictId(String districtId) {
		this.districtId = districtId;
	}

	@Column(name = "address", length = 255)
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name = "zip_code", length = 10)
	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	@Column(name = "customer_id", length = 32)
	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	@Column(name = "orders_remark", length = 255)
	public String getOrdersRemark() {
		return ordersRemark;
	}

	public void setOrdersRemark(String ordersRemark) {
		this.ordersRemark = ordersRemark;
	}
	
	@Column(name = "pay_type", length = 5)
	public String getPayType() {
		return payType;
	}

	public void setPayType(String payType) {
		this.payType = payType;
	}

	@Column(name = "invoice", length = 5)
	public String getInvoice() {
		return invoice;
	}

	public void setInvoice(String invoice) {
		this.invoice = invoice;
	}

	@Transient
	public String getMediaId() {
		return mediaId;
	}

	public void setMediaId(String mediaId) {
		this.mediaId = mediaId;
	}

	@Column(name = "nature", length = 5)
	public String getNature() {
		return nature;
	}

	public void setNature(String nature) {
		this.nature = nature;
	}

	@Column(name = "express_id", length = 32)
	public String getExpressId() {
		return expressId;
	}

	public void setExpressId(String expressId) {
		this.expressId = expressId;
	}

	@Column(name = "payment", length = 11)
	public BigDecimal getPayment() {
		return payment;
	}

	public void setPayment(BigDecimal payment) {
		this.payment = payment;
	}

	@Column(name = "freight", length = 11)
	public BigDecimal getFreight() {
		return freight;
	}

	public void setFreight(BigDecimal freight) {
		this.freight = freight;
	}

	@Column(name = "receivable", length = 11)
	public BigDecimal getReceivable() {
		return receivable;
	}

	public void setReceivable(BigDecimal receivable) {
		this.receivable = receivable;
	}

	@Column(name = "amount_paid", length = 11)
	public BigDecimal getAmountPaid() {
		return amountPaid;
	}

	public void setAmountPaid(BigDecimal amountPaid) {
		this.amountPaid = amountPaid;
	}

	@Column(name = "use_points", length = 11)
	public Integer getUsePoints() {
		return usePoints;
	}

	public void setUsePoints(Integer usePoints) {
		this.usePoints = usePoints;
	}

	@Column(name = "points", length = 11)
	public Integer getPoints() {
		return points;
	}

	public void setPoints(Integer points) {
		this.points = points;
	}

	@Column(name = "use_red", length = 11)
	public Integer getUseRed() {
		return useRed;
	}

	public void setUseRed(Integer useRed) {
		this.useRed = useRed;
	}

	@Column(name = "red", length = 11)
	public Integer getRed() {
		return red;
	}

	public void setRed(Integer red) {
		this.red = red;
	}
	
	@Column(name = "allocate_grade", length = 5)
	public String getAllocateGrade() {
		return allocateGrade;
	}

	public void setAllocateGrade(String allocateGrade) {
		this.allocateGrade = allocateGrade;
	}

	@Column(name = "hospital_id", length = 32)
	public String getHospitalId() {
		return hospitalId;
	}

	public void setHospitalId(String hospitalId) {
		this.hospitalId = hospitalId;
	}
	
	@Column(name = "center_id", length = 32)
	public String getCenterId() {
		return centerId;
	}

	public void setCenterId(String centerId) {
		this.centerId = centerId;
	}
	
	@Column(name = "group_id", length = 32)
	public String getGroupId() {
		return groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}

	@Column(name = "check_user_id", length = 32)
	public String getCheckUserId() {
		return checkUserId;
	}

	public void setCheckUserId(String checkUserId) {
		this.checkUserId = checkUserId;
	}
	
	@Transient
	public String getCenterName() {
		return centerName;
	}

	public void setCenterName(String centerName) {
		this.centerName = centerName;
	}

	@Transient
	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	@Transient
	public String getCheckUserName() {
		return checkUserName;
	}

	public void setCheckUserName(String checkUserName) {
		this.checkUserName = checkUserName;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	@Column(name = "allocate_time")
	public Date getAlloateTime() {
		return alloateTime;
	}

	public void setAlloateTime(Date alloateTime) {
		this.alloateTime = alloateTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "province_id")
	public MedicalProvince getProvince() {
		return province;
	}

	public void setProvince(MedicalProvince province) {
		this.province = province;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "city_id")
	public MedicalCity getCity() {
		return city;
	}

	public void setCity(MedicalCity city) {
		this.city = city;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "district_id")
	public MedicalDistrict getDistrict() {
		return district;
	}

	public void setDistrict(MedicalDistrict district) {
		this.district = district;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "media_id")
	public MedicalMediaInfo getMedia() {
		return media;
	}

	public void setMedia(MedicalMediaInfo media) {
		this.media = media;
	}

	@Transient
	public String getCusSerName() {
		return cusSerName;
	}

	public void setCusSerName(String cusSerName) {
		this.cusSerName = cusSerName;
	}

	@Transient
	public Date getStartTime() {
		return startTime;
	}
	
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	
	@Transient
	public Date getEndTime() {
		return endTime;
	}
	
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	
	@Transient
	public String getKeyType() {
		return keyType;
	}

	public void setKeyType(String keyType) {
		this.keyType = keyType;
	}

	@Transient
	public String getKeyPid() {
		return keyPid;
	}

	public void setKeyPid(String keyPid) {
		this.keyPid = keyPid;
	}
	
	@Transient
	public String getListType() {
		return listType;
	}

	public void setListType(String listType) {
		this.listType = listType;
	}
	
	@Transient
	public String getReasonType() {
		return reasonType;
	}

	public void setReasonType(String reasonType) {
		this.reasonType = reasonType;
	}

	@Transient
	public String getReasonRemark() {
		return reasonRemark;
	}

	public void setReasonRemark(String reasonRemark) {
		this.reasonRemark = reasonRemark;
	}

	@Transient
	public BigDecimal getTotalMoney() {
		return totalMoney;
	}

	public void setTotalMoney(BigDecimal totalMoney) {
		this.totalMoney = totalMoney;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("serialNum", serialNum);
		obj.put("name", name);
		obj.put("status", status);
		obj.put("cusSerId", cusSerId);
		obj.put("cusSerName", cusSerName);
		obj.put("customerId", customerId);
		if(null != alloateTime) {
			obj.put("alloateTime", DateFormatUtils.format(alloateTime,"yyyy-MM-dd HH:mm:ss"));
		}
		obj.put("provinceId", province.getId());
		obj.put("pName", province.getpName());
		obj.put("payType", payType);
		obj.put("cityId", city.getId());
		obj.put("cName", city.getcName());
		obj.put("districtId", district.getId());
		obj.put("dName", district.getdName());
		obj.put("contactNo", contactNo);
		obj.put("address", address);
		obj.put("zipCode", zipCode);
		obj.put("ordersRemark", ordersRemark);
		obj.put("invoice", invoice);
		obj.put("mediaId", mediaId);
		obj.put("mediaName", media.getName());
		obj.put("nature", nature);
		obj.put("expressId", expressId);
		obj.put("payment", payment);
		obj.put("freight", freight);
		obj.put("receivable", receivable);
		obj.put("amountPaid", amountPaid);
		obj.put("usePoints", usePoints);
		obj.put("points", points);
		obj.put("useRed", useRed);
		obj.put("red", red);
		obj.put("hospitalId", hospitalId);
		obj.put("groupId", groupId);
		obj.put("groupName", groupName);
		obj.put("centerId", centerId);
		obj.put("centerName", centerName);
		obj.put("checkUserId", checkUserId);
		obj.put("checkUserName", checkUserName);
		obj.put("totalMoney", totalMoney);
		obj.put("createTime", DateFormatUtils.format(createTime,"yyyy-MM-dd HH:mm:ss"));
		
		return obj.toString();
	}
}
